﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Moe_v0._1
{
    class EnInstructionFilter
    {
        private bool _isInstruction = false;
        public bool IsInstruction(string input)
        {
            // TODO: process the input string to judge whether it is an instruction and set _isInstruction.
            
            // Does segmentation and get the first word.
            StructuredSentence tokenizedInput = EnSegmentor.TokenizeSentence(input);
            string firstWord = "";
            if (tokenizedInput != null 
                && tokenizedInput.SubSentences.Count > 0 
                && tokenizedInput.SubSentences[0].PhrasePart.KeyWordList.Count > 0)
            {
                firstWord = tokenizedInput.SubSentences[0].PhrasePart.KeyWordList[0];

                // Tricky but ugly. Let's deal with some special 'verb' in the future.
                if (firstWord == "can")
                    return false;

                EnWordProperty wordProperty = EnWordDictionary.GetEnWordProperty(firstWord);
                if (wordProperty != null && wordProperty.IsVerb())
                {
                    _isInstruction = true;
                }
            }

            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("===EnInstructionFilter::IsInstruction===");
                MoeDebugger.AddDebugInfo("IsInstruction: " + _isInstruction.ToString());
                if (_isInstruction)
                {
                    MoeDebugger.AddDebugInfo(string.Format("First word '{0}' of '{1}' is a verb.",
                        firstWord, input));
                }
                MoeDebugger.AddDebugInfo("========================================");
            }
            return _isInstruction;
        }
    }
}
